package com.simple.simple_view.handler.mq;

import com.rabbitmq.client.Channel;
import com.simple.simple_view.domain.entity.Comment;
import com.simple.simple_view.domain.system.RabbitMQConstant;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.context.annotation.Configuration;

import java.io.IOException;

/*
 *@description: mq评论处理器
 *@author: hisen
 *@Time: 2023/11/2  19:53
 */
@Configuration
@Slf4j
public class RabbitMQCommentHandler {

    @RabbitListener(queues = RabbitMQConstant.QUEUE_COMMENT,ackMode = "MANUAL")
    public void onMessage(Comment comment, Message message, Channel channel){
        System.out.println(comment);
        try {
            channel.basicAck(message.getMessageProperties().getDeliveryTag(),true);
        } catch (IOException e) {
            log.error(e.getMessage(), e);
        }
    }
}
